<?php
$title="Add Recommend";
$css="AddRecommend.css";
include_once 'common/AdminTop.php';
include_once 'authentic.php';
include_once '../Class/DB.php';
$db=new DB();
$newPid=$_POST["good_id"];
$newPic=$_FILES["picurl"];
if(!isset($newPid))
{

}else if ($newPid=="")
{
	?>
	<script language="JavaScript">
	alert("Invalid product Id!");
	window.location.href="AddRecommend.php";
	</script>	
	<?php
	exit();
}else 
{
	$theNewProduct=$db->get_pid_product($newPid);
	if(!isset($theNewProduct[0]))
	{
	?>
	<script language="JavaScript">
	alert("Product Id doesn't exist!");
	window.location.href="AddRecommend.php";
	</script>	
	<?php
	exit();
	}
}

if(!isset($_POST["good_id"]))
{
	
}
else if($newPic["name"]=="")
{
	?>
	<script language="JavaScript">
	alert("Invalid picurl!");
	window.location.href="AddRecommend.php";
	</script>	
	<?php
	exit();
}


if(isset($_POST["good_id"]))//press the add button
{
	$db->Add_recommend($newPid,$newPic);
	?>
	<script language="JavaScript">
	window.location.href="others.php";
	</script>	
	<?php
	exit();
}
?>
<div class="block_context" id="modify_block" align="center">
<p style="color:red">Recommend Detail</p>
				<form enctype="multipart/form-data" action="AddRecommend.php" method="post">
					<table>
						<tr>
							<th class="t1" style="width: 150px;">
							</th>
							<th class="t2">
							</th>	
						</tr>						
						<tr>
							<td style="text-align:right;">
							<b>Product ID:</b>
							</td>
							<td style="padding-left:16px;text-align:left;"><input type="text" style="width:80px;" name="good_id"  value=""/></td>
						</tr>
						<tr>
						<td style="text-align: right;">
							<b>Path of Banner:</b>
						</td>
						<td style="padding-left:16px;text-align: left;">
						<input type="file" style="color:red;" name="picurl"  value=""/>		
						</td>
						</tr>
						</table>
						<p><input type="submit" value="Add Recommend" />
						</p>
				</form>
			</div>
<?php 
include_once 'common/AdminTail.php';
?>